﻿using System;
using Microsoft.Xna.Framework;

namespace Serious
{
    public static class Vector2Ext
    {
        public static Vector2 Rotated(this Vector2 v, Vector2 other)
        {
            Single temp;
            temp = v.X;
            v.X = v.X * other.X -  v.Y * other.Y;
            v.Y = v.Y * other.X + temp * other.Y;
            return v;
        }

        public static Single Direction(this Vector2 v)
        {
            return (Single)Math.Atan2(v.Y, v.X);
        }
        public static Single DirectionDeg(this Vector2 v)
        {
            return MathHelper.ToDegrees((Single)Math.Atan2(v.Y, v.X));
        }

        public static Vector2 FromDirection(Single direction)
        {
            return new Vector2((Single)Math.Cos(direction), (Single)Math.Sin(direction));
        }
        public static Vector2 FromDirectionDeg(Single directionDeg)
        {
            Single direction = MathHelper.ToRadians(directionDeg);
            return new Vector2((Single)Math.Cos(direction), (Single)Math.Sin(direction));
        }

        public static Vector2 Map(this Vector2 v, Func<Single, Single> f)
        {
            v.X = f(v.X);
            v.Y = f(v.Y);
            return v;
        }

        public static Vector2 Floor(Vector2 v)
        {
            return new Vector2((Single)Math.Floor(v.X), (Single)Math.Floor(v.Y));
        }
        public static Vector2 Ceiling(Vector2 v)
        {
            return new Vector2((Single)Math.Ceiling(v.X), (Single)Math.Ceiling(v.Y));
        }
        public static Vector2 Round(Vector2 v)
        {
            return new Vector2((Single)Math.Round(v.X), (Single)Math.Round(v.Y));
        }
        public static Vector2 Abs(Vector2 v)
        {
            return new Vector2(Math.Abs(v.X), Math.Abs(v.Y));
        }
    }
}
